import uvicorn
from fastapi import FastAPI
from starlette.staticfiles import StaticFiles
from tortoise.contrib.starlette import register_tortoise

from apps.shop_urls import shop
from apps.user_urls import user
from apps.tmp_urls import tmp
from apps.school_urls import school
from apps.book_urls import book

#import setting
#import mysqlconfig
import pgconfig

app = FastAPI()

register_tortoise(
    app,
    # config=setting.TORTOISE_ORM
     #config=mysqlconfig.TORTOISE_ORM
    config=pgconfig.TORTOISE_ORM
)


app.include_router(shop, prefix='/shop', tags=['商品信息'])
app.include_router(user, prefix='/user', tags=['用户信息'])
app.include_router(tmp, prefix='/tmp', tags=['模块信息'])
app.include_router(school, prefix='/school', tags=['学校信息'])
app.include_router(book, prefix='/book', tags=['书籍信息'])

#静态资源
app.mount('/static',StaticFiles(directory='static'))

@app.get("/",
         tags=['首页接口 tags'],
         summary='this is 测试summary ',
         description='this is 测试 description ',
         deprecated=True
         )
async def root():
    return {"message": "Hello World"}


@app.get("/hello/{name}")
async def say_hello(name: str):
    return {"message": f"Hello {name}"}


if __name__ == '__main__':
    uvicorn.run("main:app", port=9090)
